package trabalho.xml.gui;

import java.net.InetAddress;

import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.omg.CORBA.portable.UnknownException;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class IPSelect extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Combo cmbIP;
	private Text txtPorta;
	private Label lblIP;
	private Label lblPorta;
	private Text txtNome;
	private Label label2;
	private Button btnOK;
	public String strIP, strPorta, strNome;

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			IPSelect inst = new IPSelect(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public IPSelect(Shell parent, int style) {
		super(parent, style);
	}

	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			dialogShell.setLayout(new FormLayout());
			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(238, 171);
			{
				btnOK = new Button(dialogShell, SWT.PUSH | SWT.CENTER);
				FormData btnOKLData = new FormData();
				btnOKLData.left =  new FormAttachment(0, 1000, 86);
				btnOKLData.top =  new FormAttachment(0, 1000, 101);
				btnOKLData.width = 28;
				btnOKLData.height = 25;
				btnOK.setLayoutData(btnOKLData);
				btnOK.setText("OK");
				btnOK.addSelectionListener(new SelectionAdapter() {
					public void widgetSelected(SelectionEvent evt) {
						btnOKWidgetSelected(evt);
					}
				});
			}
			{
				label2 = new Label(dialogShell, SWT.NONE);
				FormData label2LData = new FormData();
				label2LData.left =  new FormAttachment(0, 1000, 12);
				label2LData.top =  new FormAttachment(0, 1000, 18);
				label2LData.width = 38;
				label2LData.height = 15;
				label2.setLayoutData(label2LData);
				label2.setText("Nome:");
			}
			{
				lblPorta = new Label(dialogShell, SWT.NONE);
				FormData lblPortaLData = new FormData();
				lblPortaLData.left =  new FormAttachment(0, 1000, 12);
				lblPortaLData.top =  new FormAttachment(0, 1000, 78);
				lblPortaLData.width = 31;
				lblPortaLData.height = 15;
				lblPorta.setLayoutData(lblPortaLData);
				lblPorta.setText("Porta:");
			}
			{
				lblIP = new Label(dialogShell, SWT.NONE);
				FormData lblIPLData = new FormData();
				lblIPLData.left =  new FormAttachment(0, 1000, 12);
				lblIPLData.top =  new FormAttachment(0, 1000, 45);
				lblIPLData.width = 31;
				lblIPLData.height = 15;
				lblIP.setLayoutData(lblIPLData);
				lblIP.setText("IP:");
			}
			{
				FormData txtPortaLData = new FormData();
				txtPortaLData.left =  new FormAttachment(0, 1000, 63);
				txtPortaLData.top =  new FormAttachment(0, 1000, 72);
				txtPortaLData.width = 64;
				txtPortaLData.height = 15;
				txtPorta = new Text(dialogShell, SWT.BORDER);
				txtPorta.setLayoutData(txtPortaLData);
				txtPorta.setText("404");
			}
			{
				FormData cmbIPLData = new FormData();
				cmbIPLData.left =  new FormAttachment(0, 1000, 62);
				cmbIPLData.top =  new FormAttachment(0, 1000, 41);
				cmbIPLData.width = 112;
				cmbIPLData.height = 21;
				cmbIP = new Combo(dialogShell, SWT.BORDER);
				cmbIP.setLayoutData(cmbIPLData);
				try {
					InetAddress addr = InetAddress.getLocalHost();				
					cmbIP.add(addr.getHostAddress());
					cmbIP.select(0);
				}
				catch (UnknownException e) {
					//throw e;
				}			
			}
			{
				txtNome = new Text(dialogShell, SWT.BORDER);
				FormData text1LData = new FormData();
				text1LData.left =  new FormAttachment(0, 1000, 62);
				text1LData.top =  new FormAttachment(0, 1000, 12);
				text1LData.width = 64;
				text1LData.height = 15;
				txtNome.setLayoutData(text1LData);
				txtNome.setText("G3");
			}
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void btnOKWidgetSelected(SelectionEvent evt) {
		System.out.println("btnOK.widgetSelected, event="+evt);
		//TODO add your code for btnOK.widgetSelected
			strIP = cmbIP.getText();
			strPorta = txtPorta.getText();
			strNome = txtNome.getText();
			dialogShell.close();
	}

}
